home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
58517
/
58517.xpi
/
vexpand.jar
/
content
/
vexpand.js
< prev
Wrap
Text File
|
2010-01-09
|
4KB
|
113 lines
var vexpand = {id:function(id){
return document.getElementById(id);
},
init:function(){
try{
var oContext = vexpand.id("contentAreaContextMenu");
oContext.setAttribute("onpopupshowing", "vexpand.contextShowing(event); "+ oContext.getAttribute("onpopupshowing"));
} catch(err) { alert(err); }
},
go:function(str){
opener.focus();
self.focus();
if(opener.gBrowser.addTab) {
opener.gBrowser.selectedTab = opener.gBrowser.addTab(str);
} else {
window.open(str);
}
},
getLinkInfo:function(link){
window.openDialog('chrome://vexpand/content/linkinfo.xul','VexpandLinkInfo','chrome, centerscreen, resizable', link);
},
clip:function(str, len){
if(str.length > len) return str.substr(0, len)+"...";
return str;
},
addUrlLabel:function(field, str, url){
field.setAttribute("value", str);
if(url){
field.setAttribute("style", "color: #00F; text-decoration: underline; cursor: pointer;");
field.setAttribute("title", url);
field.setAttribute("onclick", "vexpand.go('" + url + "');");
}else{
field.innerHTML = str;
}
},
getLink:function(){
if(gContextMenu != null && (gContextMenu.getLinkURL || gContextMenu.linkURL)){
return (gContextMenu.getLinkURL) ? gContextMenu.getLinkURL() : gContextMenu.linkURL;
}
return false;
},
copyCurrentAnchor:function(){
var url = vexpand.getLink();
if(url){
vexpand.copyLongUrl(url);
}
},
copyText:function(str){
try {
var clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
clipboard.copyString(str);
} catch(err) {alert(err);}
},
contextShowing:function(event){
try{
if(document.popupNode.nodeName.toUpperCase() == "A"){
vexpand.id("vexpand-context-link-menu").setAttribute("collapsed", false);
vexpand.id("vexpand-copy-link-menu").setAttribute("collapsed", false);
} else {
vexpand.id("vexpand-context-link-menu").setAttribute("collapsed", true);
vexpand.id("vexpand-copy-link-menu").setAttribute("collapsed", true);
}
} catch(err) {alert(err);}
},
getShortUrl:function(str){
var vexpandDom = {};
try{
var request = new XMLHttpRequest();
request.open( 'GET', 'http://api.voizle.com/expand?format=xml&u=' + str, false);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.send(null);
var vzdom = request.responseXML;
vexpandDom['shorturl'] = vzdom.getElementsByTagName('shorturl').item(0).childNodes[0].nodeValue;
vexpandDom['longurl'] = vzdom.getElementsByTagName('longurl').item(0).childNodes[0].nodeValue;
vexpandDom['success'] = true;
}catch(e){
vexpandDom['success'] = false;
}
return vexpandDom;
},
copyLongUrl:function(str){
try{
var vexpandUrl = vexpand.getShortUrl(str);
if(vexpandUrl.success){
vexpand.copyText(vexpandUrl.longurl);
}
}catch(e){
vexpand.copyText('http://www.voizle.com/');
}
}
}
function v_expand(link) {
try{
var longurl = vexpand.id("longurl");
var shorturl = vexpand.id("shorturl");
var url = 'http://www.voizle.com';
if(link && window.arguments[0]){
url = window.arguments[0];
}
var urlInfo = vexpand.getShortUrl(url);
if(urlInfo.success){
vexpand.addUrlLabel(longurl, urlInfo.longurl, urlInfo.longurl);
vexpand.addUrlLabel(shorturl, vexpand.clip(urlInfo.shorturl, 30), urlInfo.shorturl);
}
}catch(e){alert(vexpand.id('vexpand_strings').getString('VExpand.noconnection'));}
}